extends NodeState


@export var igorBoss: IgorBoss


var waitting_time: float

const WAITTING_TIME_THRESHOLD := 0.001


func _on_process(delta : float) -> void:
	if not igorBoss.player.enabled:
		return
	if waitting_time > WAITTING_TIME_THRESHOLD:
		waitting_time -= delta
	# 达到等待时间
	if not _changing_state and waitting_time < WAITTING_TIME_THRESHOLD:
		igorBoss.look_at_player()
		if igorBoss.is_player_within_attack_range():
			transition_state(igorBoss.next_attack_state())
		elif igorBoss.is_player_within_sprint_range():
			transition_state(IgorBoss.STATE_SPRINT)
		else:
			transition_state(IgorBoss.STATE_WALK)



func _on_enter() -> void:
	igorBoss.damageReceiver.set_deferred("monitorable", true)
	process_animation()
	random_wait()


func _on_exit() -> void:
	pass


func process_animation():
	igorBoss.animationPlayer.play(IgorBoss.ANIMATION_IDLE)


func random_wait():
	waitting_time = randf_range(igorBoss.idle_random_range.x, igorBoss.idle_random_range.y)
